package live.jialing.sip.base.domain;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import live.jialing.core.beanvalidator.Second;
import live.jialing.data.core.JpaDomainEntity;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * 学生/学籍：孩子 - 学校 - 班级的关系
 */
@Setter
@Getter
@ToString
@Entity
@Table(name = "base_student")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id", scope = Student.class)
public class Student extends JpaDomainEntity<Long> {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @NotNull(message = "id不能为空", groups = {Second.class})
    private Long id;

    /**
     * 班级中编号，学号
     */
    private String number;

    /**
     * 全国统一编号
     */
    private String serialNumber;

    /**
     * 学校
     */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "school_id", updatable = false)
    private School school;

    /**
     * 年级
     */
    private Integer grade;

    /**
     * 班级
     */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "class_id", updatable = false)
    private Squad squad;

    /**
     * 关联的孩子
     * <p>
     * 家长 N-N 孩子 1-N 学生 N-1 班级 N-1 学校
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "child_id")
    private Child child;

}
